Fix the timer plugin (init crash, missed load, unstyled)#5
Open
DmitrySharabin wants to merge 3 commits into
Open
Fix the timer plugin (init crash, missed load, unstyled)#5DmitrySharabin wants to merge 3 commits into
DmitrySharabin wants to merge 3 commits into
Conversation
The init-start handler stored duration on `this`, but the handler is a top-level arrow function, so `this` is the module's top-level value — `undefined` in ESM. It threw `TypeError: Cannot set properties of undefined` before the timer was ever created, so the timer never worked. It only worked when plugins loaded as classic scripts (top-level `this` === `window`); they now load as modules. Use a local variable instead. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The countdown started on the window `load` event, but the plugin loads asynchronously and can finish after `load` has already fired — then the listener never ran and the timer never started. Run the start logic immediately when the document is already loaded, the way the autosize plugin handles late loading. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
this is undefined in ESM)timer/plugin.css styles the #timer progress bar, but the plugin never exported `hasCSS`, so the core loader — which injects plugin.css only when `module.hasCSS` is truthy — skipped it, and the timer rendered unstyled. Export hasCSS = true, like the other CSS-bearing plugins. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The timer plugin never actually worked when loaded as an ES module. Three bugs:
1. Crash on init
init-startdidthis.duration = …, but the handler is a top-level arrow function, sothisis the module's top-level value —undefinedin ESM. It threwTypeError: Cannot set properties of undefinedbefore the timer was created. (It worked only as a classic script, where top-levelthis===window.) Fixed with a local variable.2. Countdown never started on late load
The countdown was started from
addEventListener("load", …), but the plugin loads asynchronously and can finish afterloadalready fired — then the listener never runs. Now it starts immediately whendocument.readyState === "complete", mirroring howautosizehandles late loading.3. Stylesheet never loaded
timer/plugin.cssstyles the#timerprogress bar, but the plugin didn'texport const hasCSS = true, so the core loader (which injectsplugin.cssonly whenmodule.hasCSSis truthy) skipped it — the timer rendered unstyled. Added the export.Verified (Playwright)
No crash; the timer auto-starts even when it loads after
load; the#timerbar gets its real styles fromtimer/plugin.css(the<link id="plugin-css-timer">is injected,::before"Progress" label,height: 16px, etc.); andend/overtimeclasses apply on schedule.🤖 Generated with Claude Code